using System;
using System.Web.UI.WebControls;

using Impact.Controllers;
using Impact.Model.Objects;
using Impact.Web.Foundation.Controls;

namespace Impact.Web.Admin
{
    public partial class Events : Impact.Web.Foundation.PageBase
    {

        /// <summary>
        /// overridden to handling binding on this page
        /// </summary>
        protected override void Bind()
        {
            EventCollection events = EventController.GetAllEvents();
            if ( events.Count > 0 )
            {
                eventList.DataSource = events;
                eventList.DataBind();
            }
            else
            {
                eventList.Visible = false;
                noEventsPanel.Visible = true;
            }
        }

        /// <summary>
        /// event handler for when a button is clicked in the profile listing repeater
        /// </summary>
        protected void EventList_ItemCommand( object source, RepeaterCommandEventArgs e )
        {
            switch ( e.CommandName )
            {
                case "delete":
                    EventController.DeleteEvent( e.CommandArgument.ToString() );
                    MessageBox.Show( string.Format( "Event #{0} deleted.", e.CommandArgument ) );
                    break;

                case "toggle":
                    EventController.ToggleEnabled( e.CommandArgument.ToString(), this.UserId );
                    break;

                default:
                    throw new ArgumentException( string.Format( "Command not found: {0}", e.CommandName ) );
            }
            Bind();
        }
    }
}
